home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / lists / mint / l_0399 / 186 < prev    next >
Internet Message Format  |  1994-08-27  |  8KB

  1. From: Stephen Usher <steve@earth.ox.ac.uk>
  2. Subject: Re: Shared Libraries.
  3. Date: Wed, 31 Mar 1993 09:00:04 +0100 (BST)
  4. Mime-Version: 1.0
  5.  
  6. >A Proposal for Implementing Shared Libraries
  7. >
  8. >I think I've finally figured out a "good" way to implement shared
  9. >libraries (i.e. low overhead, doesn't need VM, requires few changes
  10. >to existing applications). Here's my proposal; please let me know what
  11. >you think. (In case it isn't obvious, this is *very* far from being
  12. >cast in stone :-). I do think we need to do shared libraries soon,
  13. >though.)
  14.  
  15. I agree, shared libraries are needed soon, though maybe not before
  16. non-blocking SCSI/ACSI/IDE devices with a generic disk interface above and
  17. the filesystems above that. The current situation is rapidly becoming
  18. untenable as most of MiNT's performance degradation is with disk I/O. This
  19. will be even worse if the disk keeps on being accessed to load shared
  20. library modules on the fly.
  21.  
  22. >A shared library will be implemented as a DRI format object file, with
  23. >the GST long name symbol table. A program linked with shared libraries
  24. >will have the same format, but with an additional header prepended
  25. >which gives the names and version numbers of the shared libraries it
  26. >requires.
  27.  
  28. Hmm... why are you thinking about using such a mixed bag of formats? Why did
  29. you choose those particular formats? Why not use something like a Unix "ar"
  30. format file or similar?
  31.  
  32. >Both the libraries and the programs will be compiled to use
  33. >register A5 as a base register (e.g. when compiled with gcc they will
  34. >be compiled with -mbaserel). They need not be position independent;
  35. >the libraries will appear at the same virtual address (determined at
  36. >load time) in every process, and programs will be relocated at load
  37. >time by the kernel.
  38.  
  39. This is fine for the 68000 based Atari's, but this does seem rather cripling
  40. for the new generation of Atari's which use the 68030. I understand that
  41. you want to keep the 68000 and 68030 kernels as close as possible, but
  42. couldn't shared libraries be mapped differently on the two architectures?
  43.  
  44. What you suggest seems fine for the 68000 based machines, but for the 68030
  45. based machines it seems a bit of a munge, why not give all processes on
  46. these machines the same virtual address space and map the shared library
  47. objects into that address space?
  48.  
  49. >
  50. >The data and bss segments of a given shared library will always be
  51. >located at the same (relative) offset in the data/bss area of
  52. >a program using that library. (Note that I'm going to call the
  53. >"data/bss area" just the "data segment" from here on in, because the
  54. >bss is just a special part of the data segment from the kernel's point
  55. >of view.)
  56. >
  57. >For example, let's consider 2 programs, BAR and FOO. BAR uses libraries A,
  58. >B, and C; FOO uses A, C, and D.
  59. >
  60. >BAR's data segment will look like this: (assuming that A, B, C, and D are
  61. >the first 4 libraries loaded, and were loaded in that order)
  62. >
  63. >------------------------------------------------------------------------------
  64. >| A's data |   B's data   |   C's data  |           BAR's data               |
  65. >------------------------------------------------------------------------------
  66. >
  67. >FOO's data segment will look like this:
  68. >
  69. >------------------------------------------------------------------------------
  70. >| A's data |   FOO's data |   C's data  |  D's data  |  more of FOO's data   |
  71. >------------------------------------------------------------------------------
  72. >
  73. >Note that FOO's data segment is split up. This is because library C expects
  74. >its data to come at a certain offset (after A's and B's), and so C's data
  75. >segment in process FOO must start at that offset. Since FOO doesn't use
  76. >library B, the part of its data segment that B would normally use is
  77. >available for FOO's use. The kernel will be responsible for finding
  78. >such "holes" and taking advantage of them where possible. (This may
  79. >actually turn out to be tricky, since arrays will have to be contiguous.)
  80. >We also may want to provide a way to specify that certain libraries are
  81. >mutually exclusive. In the example above, if libraries B and D were
  82. >mutually exclusive, then D's data could occupy the same offsets as B's
  83. >(or a subset thereof, if D has less data).
  84.  
  85. It looks like you might get into a problem of massive memory fragmentation..
  86. it could get very messy. :-(
  87.  
  88. What happens if FOO needs A, B, C & D? This scheme also means that all the
  89. library modules will have to be loaded at load time instead at first call
  90. time (doesn't it?).
  91.  
  92. >
  93. >Does this make sense? The key thing is that since everyone is using
  94. >register A5 as a base register, the libraries can always find their
  95. >data (at the particular fixed offset into the data segment assigned to
  96. >them).
  97. >
  98. >The disadvantage of this scheme is that once more than 64K of data is
  99. >filled up, libraries and/or programs that use 16 bit offsets will be
  100. >in trouble. There are ways around this, of course.
  101.  
  102. Yes, but they are probably cludges!
  103.  
  104. >
  105. >Another disadvantage is that program load times will be longer, since
  106. >the kernel is going to have to do the relocation and symbol resolving.
  107. >
  108. >An alternative would be to use something like Sun's global offset table.
  109. >That scheme is slower, though, since it adds another layer of indirection
  110. >to variable references.
  111.  
  112. It may be slower (slightly), but at least it is very flexible in that you
  113. only have to initialise the offset on the first call of the module when it
  114. is loaded. Also this method would work just as well in a virtual address
  115. space, except you'd give a virtual address of the module. What size of
  116. offset were you thinking of having? 16bit? 32bit?  Depends upon architecture?
  117.  
  118. >Please let me know your thoughts on this matter.
  119. >
  120. >Eric
  121.  
  122. How about an alternative....
  123.  
  124. (1) Have in the kernel a table of currently loaded modules, each with a
  125.     reference count.
  126. (2) Modules are loaded into an arbitary memory location with a read-only
  127.     copy of their initialised data space at the time of first reference
  128.     and a copy of the initialised data space is placed in the process'
  129.     shared lib data segment, which is separate from it's own data
  130.     segment. The total size of the shared library data segment is 64K on
  131.     the 68000 based machines and "unlimited" on 68030 based machines,
  132.     there is no limit imposed upon the normal data segment. Shared data
  133.     is accessed via an offset table.
  134. (3) Modules are deleted once the last program to use them exits, or
  135.     alternatively... The kernel table has a timer which is added to
  136.     every time a module is accessed. After n context switches, any
  137.     module which has not been accessed in that time could be deleted
  138.     from memory and a flag in the table set to say that the module is
  139.     active but not in memory. When the module is next accessed, it is
  140.     re-loaded, but the data space is not copied to the currently running
  141.     program. This would improve memory usage no end, especially if
  142.     modules were of a fixed size or a multiple of a fixed size, no
  143.     memory fragmentation! This would give a sort of virtual memory even
  144.     for 68000 based machines.
  145.  
  146. I understand the problems with this method, ie each shared library call has
  147. a system call overhead etc. But there is a major advantage in that loaded
  148. programs which are only using a small number of their routines in a small
  149. loop would rapidly reduce in memory usage, allowing other programs to use
  150. the memory for their routines.
  151.  
  152. You do realise the case I'm thinking of is X-Windows, don't you? :-)
  153.  
  154. Just think, the majority of X applications would be sitting waiting for
  155. input in one routine from a shared library, taking up very little memory.
  156.  
  157. I've thought this up on the fly, so there could be massive holes in my
  158. arguments, oh well, it seems like a good idea at the moment.
  159.  
  160. Steve
  161.  
  162. -- 
  163. ---------------------------------------------------------------------------
  164. Computer Systems Administrator, Dept. of Earth Sciences, Oxford University.
  165. E-Mail: steve@uk.ac.ox.earth (JANET) steve@earth.ox.ac.uk (Internet).
  166. Tel:- Oxford (0865) 282110 (UK) or +44 865 282110 (International).
  167.